package com.businessportal.web.dataaccess.services;

import com.businessportal.web.dataaccess.dao.BlogEntityDao;
import com.businessportal.web.dataaccess.dao.IBlogEntityDao;
import com.businessportal.web.dataaccess.entities.BlogEntity;
import com.businessportal.web.dataaccess.entities.Login;

import java.util.List;
import java.util.Set;

/**
 * Created by Vadim on 6/27/14.
 */
public enum BlogEntityService {

    INSTANCE;

    private IBlogEntityDao dao = new BlogEntityDao();

    private BlogEntityService(){

    }

    public BlogEntity AddNewBlog(String blogTitle, String blogText, Login currentUser, boolean isPrivate){
        BlogEntity bl = new BlogEntity();
        bl.setOwner_id(currentUser.getId());
        bl.setBlogText(blogText);
        bl.setBlogTitle(blogTitle);
        bl.setPrivate(isPrivate);
        dao.save(bl);
        return  bl;
    }

    public BlogEntity getBlogById(Long id){
        return dao.getById(id);
    }

    public void updateBlog(BlogEntity blog){
        dao.update(blog);
    }

    public Set<BlogEntity> getBlogsForUser(Login user){
        return dao.getBlogEntitiesForUser(user);
    }

    public void deleteBlogById(Long id){
        dao.deleteById(id);
    }

    public Set<BlogEntity> getAllPublicBlogs(){
        return dao.getAllPublicBlogEntities();
    }
}
